package com.jjshop.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Colin on 15/12/15.
 */
public class PreUtils {

    public static final String PREF_NAME = "config";
    public static final String PIC_SOURCE_TRANSBASE = "pic_source_transbase";
    public static final String AVATAR_1 = "avatar_l";
    public static final String SEX = "sex";
    public static final String NICKNAME = "nickname";
    public static final String PROVINCE = "province";
    public static final String CITY = "city";
    public static final String AREA = "area";
    public static final String INTRO = "intro";
    public static final String SIGNATURE = "signature";
    public static final String LOGIN_TYPE = "login_type";
    public static final String COOKIE_TOKEN = "cookie_token";
    public static final String HOUR = "hour";
    public static final String TAGRESPONSE = "tagResponse";
    public static final String USER_BASE_URL = "USER_BASE_URL";
    public static final String BASE_URL = "BASE_URL";
    public static final String GROUP_ID = "group_id";
    public static final String COME_INDICATOR = "come_indicator";
    public static final String DISTRING = "distring";
    public static final String HOME_RESPONSE = "home_response";
    public static final String IS_SIGN_ON = "is_sign_on";
    public static final String DAY = "day";
    public static final String USER_ACCESS_TOKEN = "user_access_token";
    public static final String REGID = "regId";
    public static final String HUAWEIPUSH = "huaweipush";
    public static final String VIDEO_BG = "video_bg";
    public static final String VIDEO_HEAD = "video_head";
    public static final String IS_AUTH = "is_auth";
    public static final String JJMAIL = "jj_mail";
    public static final String USER_MOBILE = "user_mobile";
    public static final String USER_AUTH = "user_auth";
    public static final String USER_ID = "user_id";
    public static final String SHOW_JJMAIL = "show_jjmail";//1 shi  0 否
    public static final String SHOP_ID = "shop_id";
    public static final String SHOP_NAME = "shop_name";
    public static final String SHOP_INFO = "shop_info";
    public static final String SHOP_LOGO = "shop_logo";
    public static final String SHOP_IMG = "shop_img";

    public static boolean getBoolean(Context ctx, String key, boolean defaultValue) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return sp.getBoolean(key, defaultValue);
    }

    public static void setBoolean(Context ctx, String key, boolean value) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putBoolean(key, value).commit();
    }

    public static String getString(Context ctx, String key, String defaultValue) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return sp.getString(key, defaultValue);
    }

    public static void setString(Context ctx, String key, String value) {
        if (ctx == null){
            return;
        }
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        sp.edit().clear();
        sp.edit().putString(key, value).commit();
    }

    public static int getInt(Context ctx, String key, int defaultValue) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return sp.getInt(key, defaultValue);
    }

    public static void setInt(Context ctx, String key, int value) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        sp.edit().putInt(key, value).commit();
    }

    public static long getLong(Context ctx, String key, long defaultValue) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return sp.getLong(key, defaultValue);
    }

    public static void setLong(Context ctx, String key, long value) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        sp.edit().putLong(key, value).commit();
    }

    public static float getFloat(Context ctx, String key, float defaultValue) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return sp.getFloat(key, defaultValue);
    }

    public static void setFloat(Context ctx, String key, float value) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        sp.edit().putFloat(key, value).commit();
    }

    /**
     * 设置缓存 key 是url, value是json
     */
    public static void setCache(String key, String value, Context ctx) {
        setString(ctx, key, value);
        //可以将缓存放在文件中, 文件名就是Md5(url), 文件内容是json
    }

    /**
     * 获取缓存 key 是url
     */
    public static String getCache(String key, Context ctx) {
        return getString(ctx, key, null);
    }


    //舞队名称
    public static final String TEAM_NAME = "team_nmae";
    public static final String UAUTH = "_uauth";
    public static final String DEVICE = "device";
    public static final String ROLE_ID = "role_id";
    public static final String UPDATE_DIALOG = "update_dialog";
    public static final String TEAM_ID = "team_id";
    public static final String LATITUDE = "latitude";
    public static final String LONTITUDE = "lontitude";
    public static final String UID = "uid";
    //版本codeversion
    public static final String VERSION = "up_version";

}
